import 'package:flutter/material.dart';
import 'package:get/get.dart';
//import 'package:hive_flutter/adapters.dart';
import 'lang/enUS.dart';
import 'lang/zhCN.dart';
import 'lang/zhHant.dart';

class LocalizationService extends Translations {
  //final box = Hive.box('appconfig');
  static const defaultLocale = Locale('en', 'US');
  static const fallbackLocal = Locale('en', 'US');
  static const localeLangs = ['ENG', '简体', '繁体'];
  static final localLocales = [
    Locale('en', 'US'),
    Locale('zh', 'CN'),
    Locale('zhHant', 'TW')
  ];
  @override
  Map<String, Map<String, String>> get keys =>
      {'en': enUS, 'zh': zhCN, 'zhHant': zhHant};

  void changeLocale(String lang) {
    var locale = _getLocaleFromLanguage(lang);
    Get.updateLocale(locale);
  }

  Locale _getLocaleFromLanguage(String lang) {
    // var profile =
    //     json.decode(box.get(CacheManagerKey['profilesettings'].toString()));
    // if (interfaceChinese) {
    //   for (int i = 0; i < localeChineseLangs.length; i++) {
    //     if (lang == localeChineseLangs[i]) return localChineseLocales[i];
    //   }
    //   return Get.locale ?? defaultChineseLocale;
    // } else {
    //   for (int i = 0; i < localeLangs.length; i++) {
    //     if (lang == localeLangs[i]) return localLocales[i];
    //   }
    //   return Get.locale ?? defaultLocale;
    // }
    for (int i = 0; i < localeLangs.length; i++) {
      if (lang == localeLangs[i]) return localLocales[i];
    }
    return Get.locale ?? defaultLocale;
  }
}
